package adapter;

import model.Store;

import com.example.lastprojectbeautiplus.R;
import com.squareup.picasso.Picasso;

import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class StoreListViewAdapter extends BaseAdapter {
	private Context context;
	private Store[] storeList;
	public StoreListViewAdapter(Context context, Store[] storeList){
		this.context = context;
		this.storeList = storeList;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return storeList.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView == null) {
            LayoutInflater mInflater = (LayoutInflater)
                    context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            convertView = mInflater.inflate(R.layout.store_list_view_item, null);
        }
		DisplayMetrics metrics = convertView.getResources().getDisplayMetrics();
        int width;
        width = metrics.widthPixels;
        //height = metrics.heightPixels;
		ImageView imgLogo = (ImageView) convertView.findViewById(R.id.imgLogoStore);
		TextView tvName = (TextView) convertView.findViewById(R.id.tvStoreName);
		tvName.setText(storeList[position].getStoreName());
		String url = storeList[position].getLogo_path();
		imgLogo.getLayoutParams().height = width/4;
		imgLogo.getLayoutParams().width = width/4;
		Picasso.with(context).load(url).placeholder(R.drawable.image_wait).into(imgLogo);
		return convertView;
	}

}
